package edu.core;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * 日期处理类.
 *
 * @author weidong
 */
public class DateUtil {
	private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
	private static SimpleDateFormat sdf2 = new SimpleDateFormat("yyyyMMdd");
	private static SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss a");
	private static SimpleDateFormat sdf3 = new SimpleDateFormat("yyMMdd");
	private static SimpleDateFormat sdf4 = new SimpleDateFormat("yyMMddHH");
	private static SimpleDateFormat sdfCN = new SimpleDateFormat("yyyy年MM月dd日");
	private static SimpleDateFormat sdfYearMonth = new SimpleDateFormat("yyyyMM");
	private static SimpleDateFormat sdfYearMonth1 = new SimpleDateFormat("yyMM");
	private static SimpleDateFormat mmdd = new SimpleDateFormat("MMdd");
	private static SimpleDateFormat longSDF = new SimpleDateFormat("yyyyMMddHHmmssS");

	/**
	 * 将字符型日期转为日期型 年月日 时分秒yyyy-MM-dd hh:mm:ss.
	 *
	 * @param date
	 * @return
	 */
	public static final Date stringToDate(String date) {
		Date dt = null;
		try {
			dt = sdf1.parse(date);
		} catch (ParseException e) {
			return null;
		}
		return dt;
	}
	
	/**
	 * 将字符型日期转为日期型 yyyyMMdd
	 *
	 * @param date
	 * @return
	 */
	public static Date stringToDate2(String date) {
		Date dt = null;
		try {
			dt = sdf2.parse(date);
		} catch (ParseException e) {
			return null;
		}
		return dt;
	}
	
    /**
	 * 将字符型日期转为日期型 yyyy-MM-dd
	 *
	 * @param date
	 * @return
	 */
	public static Date stringToDate3(String date) {
		Date dt = null;
		try {
			if (date != null) {
				dt = sdf.parse(date);
			}

		} catch (ParseException e) {
			return null;
		}
		return dt;
	}

    /**
	 * 将字符型日期转为日期型 yyyy年MM月dd日
	 *
	 * @param date
	 * @return
	 */
	public static Date stringToDate4(String date) {
		Date dt = null;
		try {
			dt = sdfCN.parse(date);

		} catch (ParseException e) {
			return null;
		}
		return dt;
	}
	
	/**
	 * 将日期型转为字符型 yyyy-MM-dd
	 *
	 * @param date
	 * @return
	 */
	public static String dateToString(Date date) {
		String dt = null;
		dt = sdf.format(date);
		return dt;
	}
	
	/**
	 * 将日期型转为字符型 yyyyMMdd
	 * 
	 * @param date
	 * @return
	 */
	public static String dateToString2(Date date) {
		String dt = null;
		dt = sdf2.format(date);
		return dt;
	}
	
	/**
	 * 将日期型转为字符型 yyMMdd
	 *
	 * @param date
	 * @return
	 */
	public static String dateToString3(Date date) {
		String dt = null;
		dt = sdf3.format(date);
		return dt;
	}
	
   /**
	 * 将日期型转为字符型 yyyyMM
	 *
	 * @param date
	 * @return yearmonth
	 * @author liulonghua
	 */
    public static String dateToString5(Date date) {
		String dt = null;
		dt = sdfYearMonth.format(date);
		return dt;
	}
	
    /**
	 * 将日期型转为字符型 yyMM
	 * 
	 * @param date
	 * @return yearmonth
	 * @author liulonghua
	 */
    public static String dateToString6(Date date) {
		String dt = null;
		dt = sdfYearMonth1.format(date);
		return dt;
	}
    
    /**
	 * 将日期型转为字符型 mmdd
	 * 
	 * @param date
	 * @return yearmonth
	 * @author liulonghua
	 */
    public static String dateToString7(Date date) {
		String dt = null;
		dt = mmdd.format(date);
		return dt;
	}
    
    /**
	 * 将日期型转为字符型 yyMMddHHmmss
	 * 
	 * @param date
	 * @return yearmonth
	 * @author liulonghua
	 */
    public static String dateToString8(Date date) {
		String dt = null;
		dt = sdf4.format(date);
		return dt;
	}
    
	
	/**
	 * 将日期型转为字符型 yyyy年MM月dd日
	 * 
	 * @param date
	 * @return
	 */
	public static String dateToStringCN(Date date) {
		String dt = null;
		dt = sdfCN.format(date);
		return dt;
	}
	
	/**
	 * 将日期型转为字符型
	 * yyyy-MM-dd hh:mm:ss a
	 * @param date
	 * @return
	 */
	public static String formatTime(Date date) {
		String dt = null;
		dt = sdf1.format(date);
		return dt;
	}

	/**
	 * 返回长格式的一个日期(yyyyMMddHHmmssS).
	 *
	 * @author weidong
	 * @return
	 */
    public static String getLongDateTime() {
    	return longSDF.format(new Date());
    }
}
